{{include file="Manage/header.html"}}
<body>
{{include file="Manage/menu.html"}}
<div class="index_main">
    {{include file="Manage/menu2.html"}}
    <div class="personal_main">
        <div class="center">
            <form method="post" onsubmit="return false" action="index.php?app=Personal&act=image">
                <div class="portrait">
                    <img src="{{$result.image|photo}}" id="pic">
                    <input id="upload" name="file" accept="image/*" style="display: none" type="file">
                    <div class="mask"></div>
                    <input type="hidden" name="image" value="{{if $result.image}}{{$result.image}}{{/if}}">
                </div>
                <p class="img_note">上传图片类型为jpg，png，jpeg，最大不得超过2M</p>
                <div class="edit">
                    <div class="go_edit">
                        <img src="{{$smarty.const.__APP__}}/manage/images/go_edit.png">
                    </div>
                    <ul>
                        <li>
                            真实姓名<input name="username" value="{{$result.username}}" readonly="true">
                        </li>
                        {{if $result.type == '2'}}
                        <li>
                            &emsp;&emsp;学号<input name="params[student_id]" value="{{$result.params.student_id}}" readonly="true">
                        </li>
                        {{/if}}
                        <li>
                            所属院系
                            {{if $result.type != '0'}}
                            <select name="college" id="change_college" disabled="true">
                                {{foreach from=$result.colleges item=val key=key}}
                                <option value="{{$val.id}}" {{if $result.college == $val.id}}selected="true"{{/if}}>{{$val.title}}</option>
                                {{/foreach}}
                            </select>
                            {{else}}
                            &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp{{$result.college_c}}
                            {{/if}}
                        </li>
                        {{if $result.type == '2'}}
                        <li>
                            &emsp;&emsp;专业
                            <select name="class" id="change_class" disabled="true">
                                {{foreach from=$result.classes item=val key=key}}
                                <option value="{{$val.id}}" {{if $result.class == $val.id}}selected="true"{{/if}}>{{$val.title}}</option>
                                {{/foreach}}
                            </select>
                        </li>
                        {{/if}}
                        {{if $result.type != '0'}}
                        <li>
                            &emsp;手机号<input name="number" value="{{$result.number}}" readonly="true">
                        </li>
                        {{/if}}
                        <li>
                            电子邮箱<input name="email" value="{{$result.email}}" readonly="true">
                        </li>
                    </ul>
                    <div>
                        <button onclick="modify()">保存</button>
                        <button id="cancel">取消</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
</div>
<script>

    $(function () {
        $(".go_edit").click(function () {
            $(".go_edit").hide();
            $(".edit").find("div:last").show();
            $(".edit").find("input").attr("readonly",false);
            $("#change_college").attr("disabled", false);
            $("#change_class").attr("disabled", false);
            $(".mask").css("display","none");
            $(".img_note").css("display","block");
        })
        $("#cancel").click(function () {
            $(".edit").find("div:last").hide();
            $(".go_edit").show();
            $(".edit").find("input").attr("readonly",true);
            $("#change_college").attr("disabled", true);
            $("#change_class").attr("disabled", false);
            $(".mask").css("display","block");
            $(".img_note").css("display","none");
        })
    })

    function modify(){
        var params = $("form").serialize();
        $.post('{{"index.php?app=Personal&act=setting"|URL}}',params,function(result){
            if(result.statusCode=='200'){
                ui.success(result.message);
                setTimeout(function(){
                    location.reload();
                },1000);
            }else if(result.statusCode=='300') ui.error(result.message);
        },'json');
    }

    //院系改变
    $("#change_college").change(function(){
        var id = $(this).val();
        $.get('{{"index.php?app=Login&act=getclass"|URL}}',{'id':id},function(result){
            if(result.statusCode == '200'){
                $("#change_class").html(result.message).trigger("chosen:updated");
            }
        },'json');
    })

    //图片
    $("#upload").change(function(){
        $("form").ajaxSubmit({
            dataType:  'json',
            success: function(result) {
                if(result.statusCode == '200')
                    $("input[name=image]").val(result.message);
                else if(result.statusCode == '300'){
                    $("input[name=image]").val("{{$result.image}}");
                    $("#pic").attr('src',"{{$result.image|photo}}");
                    ui.error(result.message);
                }
            }
        });
    });
</script>
{{include file="Manage/footer.html"}}